﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;

public partial class admin_xsgl_tjxszh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin_id"] == null)
        {
            Response.Redirect("admin_logout.aspx");
            return;
        }
    }

    protected void btAdd_Click(object sender, EventArgs e)
    {
        string account = this.tbName.Text.Trim();
        string password = this.tbPwd.Text.Trim();
        string conpassword = this.conPwd.Text.Trim();     
        bool bl = false;
        string created_by;
        int id;
        int count;
        AdminBT at=new AdminBT ();
        StudentBT st = new StudentBT();
        DataTable dt = st.FindByAccount(account);
        if (dt == null)
        {
            count = -1;
        }
        else if(dt.Rows .Count ==0)
        {
            count = 0;
        } 
        else 
        {
            count = 1;
        }        
        if (account .Trim ().Length  == 0)
        {
            this.lb1.Text = "账号不能为空";
            return;
        }
        else if (count==1)
        {
            this.lb1.Text = "账号已存在，请重新选择";
            return;
        }
        else if(count ==-1)
        {
            this.lb1.Text = "判断账号逻辑错误，操作失败";
        }
        else if (password.Trim().Length == 0)
        {
            this.lb2.Text = "密码不能为空";
            return;
        }
        else if (password != conpassword)
        {
            this.lb3.Text = "两次密码输入不一致";
            return;
        }
        else
        {

            id = int.Parse(Session["admin_id"].ToString());
            created_by =at.FindbyId (id);
            bl = st.InsertStudent(account ,password ,created_by );
        }
        if (bl)
        {
            message_show("添加成功");
            return;
        }
        else
        {
            message_show("操作失败");
            return;
        }

    }

    /// <summary>
    /// 信息提示
    /// </summary>
    /// <param name="msg">提示信息</param>
    private void message_show(string msg)
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "信息提示", "<script language='javascript'>  warning('" + msg + "');</script>");
    }
}
